/**
 * Created by IntelliJ IDEA.
 * User: niklaas
 * Date: 5-mrt-2009
 * Time: 13:31:32
 * To change this template use File | Settings | File Templates.
 */
package com.compomics.prioritizer.general;

import org.masukomi.aspirin.core.MailWatcher;
import com.compomics.prioritizer.db.accessors.User;
import com.compomics.prioritizer.general.gui.MailSendingPanel;

import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.Vector;

public class PrioritizerSingelton {


    private User iUser;

    private Vector<MailSendingPanel> lMailSendingPanels = new Vector<MailSendingPanel>();

    private static PrioritizerSingelton ourInstance = new PrioritizerSingelton();

    private String iUserEmailAdress;
    private String iSMTP_HOST_NAME;
    private String iSMTP_PORT;
    private String iSSL_FACTORY;
    private String iADDRESS;
    private String iPass;


    public static PrioritizerSingelton getInstance() {
        return ourInstance;
    }

    private PrioritizerSingelton() {
        loadProperties();
    }


    public User getUser() {
        return iUser;
    }

    public void setUser(User iUser) {
        this.iUser = iUser;
        iUserEmailAdress = iUser.getE_mail();
    }

    public void addMailSendingPanel(MailSendingPanel lPanel){
        this.lMailSendingPanels.add(lPanel);
    }

    public String getUserEmailAdress() {
        return iUserEmailAdress;
    }

    public void setUserEmailAdress(String iUserEmailAdress) {
        this.iUserEmailAdress = iUserEmailAdress;
    }

     /**
     * Load the properties from icelogo.properties.
     */
    public void loadProperties() {
        // Read properties file.
        Properties properties = new Properties();

        try {
            // Attempt to load the properties.
            properties.load(ClassLoader.getSystemResourceAsStream("prioritizer.properties"));

            iSMTP_HOST_NAME = String.valueOf(properties.get("SMTP_HOST_NAME"));
            iSMTP_PORT  = String.valueOf(properties.get("SMTP_PORT"));
            iSSL_FACTORY  = String.valueOf(properties.get("SSL_FACTORY"));
            iADDRESS = String.valueOf(properties.get("ADDRESS"));
            iPass = String.valueOf(properties.get("PASS"));




        } catch (IOException e) {
            // Failed to load params from classpath, don't mind because it will be created asap.
        } catch (NullPointerException e){
            // Failed to load params from classpath, don't mind because it will be created asap.
        }
    }


    public String getSMTP_HOST_NAME() {
        return iSMTP_HOST_NAME;
    }

    public String getSMTP_PORT() {
        return iSMTP_PORT;
    }

    public String getSSL_FACTORY() {
        return iSSL_FACTORY;
    }

    public String getADDRESS() {
        return iADDRESS;
    }

    public String getPass() {
        return iPass;
    }
}
